package com.javasm.Service;

import com.javasm.entity.LoginUser;
import com.javasm.entity.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
@Component
public class LoginPhoneService implements UserDetailsService {


    @Resource
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String phone) throws UsernameNotFoundException {
        User user = userService.getByPhone(phone);
        LoginUser loginUser=new LoginUser();
        loginUser.setUser(user);
        loginUser.setPermissions(userService.getFunctions(user.getId()));
        return loginUser;
    }
}
